from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.schedulers.blocking import BlockingScheduler
import datetime

from .ScheduleViews import refreshCouponStatus
from ..utils.func import getCurrentTime


def startSchedule():
    scheduler = BackgroundScheduler()
    # 添加任务
    scheduler.add_job(func=couponFunction, args=('优惠券',), trigger='cron', day='*/1')
    # scheduler.add_job(func=aps_test, args=('一次性任务',), next_run_time=datetime.datetime.now() + datetime.timedelta(seconds=12))
    # scheduler.add_job(func=aps_test, args=('循环任务',), trigger='interval', seconds=3)
    # 启用定时任务
    scheduler.start()

# 检测优惠券是否过期
def couponFunction(name):
    print(name+"任务正在启用:"+getCurrentTime())
    refreshCouponStatus()